package servletClasses;


import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import connection.DBConnection;

import daoClasses.Query;

@WebServlet("/IU_ProfileServlet")
public class IU_ProfileServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public IU_ProfileServlet() 
    {
        super();
    }
    String acc_holder_id;
    String f_name;
    String m_name;
    String l_name;
    String dob;
    String indian_citizen;
    String address;
    int phn;
    String email;
    String pan;
    String demat;
    String gender;
    String state;
    String city;
    
    Query q= new Query();
    HttpSession session;
    Statement stat = null;
    Connection con = null;
    ResultSet rs = null;
    
    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException 
	{
			doPost(req,res);
	}
	protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException 
	{
		System.out.println("IN IU_ProfileServlet");
		session = req.getSession(true);
		String uname = (String) session.getAttribute("uname1");
		System.out.println("Your ID is"+uname);
		session.setAttribute("uname", uname);
		
		try {
			con=DBConnection.createConnection();
			stat=con.createStatement();
			rs=stat.executeQuery(q.iuProfile("uname"));
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		try {
			while(rs.next())
			{
				 acc_holder_id = rs.getString("acc_holder_id");
			     f_name = rs.getString("f_name");
			     m_name = rs.getString("m_name");
			     l_name = rs.getString("l_name");
			     dob = rs.getString("dob");
			     indian_citizen = rs.getString("indian_citizen");
			     address = rs.getString("address");
			     phn = rs.getInt("phn");;
			     email = rs.getString("email");;
			     pan = rs.getString("pan");;
			     demat = rs.getString("demat");;
			     gender = rs.getString("gender");;
			     state = rs.getString("state");;
			     city = rs.getString("city");;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		session.setAttribute("acc_holder_id", acc_holder_id);
		session.setAttribute("f_name", f_name);
		session.setAttribute("m_name", m_name);
		session.setAttribute("l_name", l_name);
		session.setAttribute("dob", dob);
		session.setAttribute("indian_citizen", indian_citizen);
		session.setAttribute("address", address);
		session.setAttribute("phn", phn);
		session.setAttribute("email", email);
		session.setAttribute("pan", pan);
		session.setAttribute("demat", demat);
		session.setAttribute("gender", gender);
		session.setAttribute("state", state);
		session.setAttribute("city", city);
		req.getRequestDispatcher("/IU_Profile.jsp").forward(req, res);
	}
}
